package com.sicau.socialpracticesystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sicau.socialpracticesystem.entity.param.PageParam;
import com.sicau.socialpracticesystem.entity.po.Grade;
import com.sicau.socialpracticesystem.entity.vo.PageDataVO;
import com.sicau.socialpracticesystem.mapper.GradeMapper;
import com.sicau.socialpracticesystem.service.GradeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sicau.socialpracticesystem.util.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 年级表 服务实现类
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2021-04-26
 */
@Service
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade> implements GradeService {

    @Resource
    private GradeMapper gradeMapper;

    @Override
    public PageDataVO<Grade> queryGradesByPage(PageParam pageParam) {
        Page<Grade> gradePage = gradeMapper.selectPage(
                new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()),
                new LambdaQueryWrapper<Grade>().orderByDesc(Grade::getId));
        return PageUtil.convert(gradePage);
    }

    @Override
    public List<Grade> queryGrades() {
        return gradeMapper.selectList(new LambdaQueryWrapper<Grade>().orderByDesc(Grade::getId));
    }
}
